package com.finance.rule.service;

import com.finance.framework.lang.Page;
import com.finance.framework.lang.PageResultBO;
import com.finance.rule.bean.pojo.MajorRuleLog;
import com.finance.rule.bean.pojo.PieceRuleLog;
import com.finance.rule.bean.pojo.WeightRuleLog;
import com.finance.rule.dao.RuleLogMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: ly
 * @Date: Created in 2017/08/16
 */
@Service
public class RuleLogService implements IRuleLogService {
    @Autowired
    private RuleLogMapper ruleLogMapper;

    /*
    @Autowired
    private SupplierMapper supplierMapper;

    @Autowired
    private CarrierMapper carrierMapper;

    @Autowired
    private RegionCodeMapper regionCodeMapper;

    @Autowired
    private SettlementRegionMapper settlementRegionMapper;
    */

    @Override
    public List<String> getMajorRuleVersionList(){
        return this.ruleLogMapper.getMajorRuleVersionList();
    }

    @Override
    public List<String> getWeightRuleVersionList(){
        return this.ruleLogMapper.getWeightRuleVersionList();
    }

    @Override
    public List<String> getPieceRuleVersionList(){
        return this.ruleLogMapper.getPieceRuleVersionList();
    }

    @Override
    public PageResultBO<MajorRuleLog> majorRuleLogListByPage(Page page) {
        PageResultBO<MajorRuleLog> pageResultBO = new PageResultBO<MajorRuleLog>();
        List<MajorRuleLog> majorRuleLogs = ruleLogMapper.majorRuleLogListByPage(page);
        pageResultBO.setPageSize(page.getPageSize());
        pageResultBO.setPageNo(page.getPageNo());
        pageResultBO.setTotalRecord(page.getTotalRecord());
        pageResultBO.setDataList(majorRuleLogs);
        return pageResultBO;
    }

    @Override
    public PageResultBO<PieceRuleLog> pieceRuleLogListByPage(Page page) {
        PageResultBO<PieceRuleLog> pageResultBO = new PageResultBO<PieceRuleLog>();
        List<PieceRuleLog> pieceRuleLogs = ruleLogMapper.pieceRuleLogListByPage(page);
        pageResultBO.setPageSize(page.getPageSize());
        pageResultBO.setPageNo(page.getPageNo());
        pageResultBO.setTotalRecord(page.getTotalRecord());
        pageResultBO.setDataList(pieceRuleLogs);
        return pageResultBO;
    }

    @Override
    public PageResultBO<WeightRuleLog> weightRuleLogListByPage(Page page) {
        PageResultBO<WeightRuleLog> pageResultBO = new PageResultBO<WeightRuleLog>();
        List<WeightRuleLog> weightRuleLogs = ruleLogMapper.weightRuleLogListByPage(page);
        pageResultBO.setPageSize(page.getPageSize());
        pageResultBO.setPageNo(page.getPageNo());
        pageResultBO.setTotalRecord(page.getTotalRecord());
        pageResultBO.setDataList(weightRuleLogs);
        return pageResultBO;
    }

    /*@Override
    public PageResultBO<MajorRuleLog> majorRuleLogListByPage(Page page) {
        PageResultBO<MajorRuleLog> pageResultBO = new PageResultBO<MajorRuleLog>();
        List<MajorRuleLog> MajorRuleLogs = ruleLogMapper.majorRuleLogListByPage(page);
        List<MajorRuleLog> MajorRuleLogArrayList = new ArrayList<>();
        for( MajorRuleLog MajorRuleLog : MajorRuleLogs){
            MajorRuleLog MajorRuleLog1 = JSON.toJavaObject(JSON.parseObject(MajorRuleLog.getSnapshot()), MajorRuleLog.class );
            MajorRuleLog1.setCreateTime(MajorRuleLog.getCreateTime());
            MajorRuleLog1.setCalculateType(MajorRuleLog.getCalculateType());
            MajorRuleLog1.setChangeType(MajorRuleLog.getChangeType());
            MajorRuleLog1.setCreateUName(MajorRuleLog.getCreateUName());
            MajorRuleLog1.setVersion(MajorRuleLog.getVersion());
            MajorRuleLog1.setSupplierName(supplierMapper.getNameByCode(MajorRuleLog1.getSupplierCode()));
            MajorRuleLog1.setCarrierName(carrierMapper.getNameByCode(MajorRuleLog1.getCarrierCode()));
            if( MajorRuleLog1.getFromProvince() != null ){
                MajorRuleLog1.setFromProvinceName(regionCodeMapper.getNameByCode(MajorRuleLog1.getFromProvince()));
            }
            if( MajorRuleLog1.getFromCity() != null ){
                MajorRuleLog1.setFromCityName(regionCodeMapper.getNameByCode(MajorRuleLog1.getFromCity()));
            }
            if( MajorRuleLog1.getToProvince() != null ){
                MajorRuleLog1.setToProvinceName(regionCodeMapper.getNameByCode(MajorRuleLog1.getToProvince()));
            }
            if( MajorRuleLog1.getToCity() != null ){
                MajorRuleLog1.setToCityName(regionCodeMapper.getNameByCode(MajorRuleLog1.getToCity()));
            }
            if(StringUtils.isNotBlank(MajorRuleLog1.getRegionId()) ){
                MajorRuleLog1.setRegionType(settlementRegionMapper.getLevelById(MajorRuleLog1.getRegionId()));
            }
            MajorRuleLogArrayList.add(MajorRuleLog1);
        }

        pageResultBO.setPageSize(page.getPageSize());
        pageResultBO.setPageNo(page.getPageNo());
        pageResultBO.setTotalRecord(page.getTotalRecord());
        pageResultBO.setDataList(MajorRuleLogArrayList);
        return pageResultBO;
    }*/

    /*@Override
    public PageResultBO<ComputeRuleLog> computeRuleLogListByPage(Page page) {
        PageResultBO<ComputeRuleLog> pageResultBO = new PageResultBO<ComputeRuleLog>();
        List<ComputeRuleLog> dragRuleLogLists = ruleLogMapper.computeRuleLogListByPage(page);
        if(dragRuleLogLists != null && dragRuleLogLists.size() > 0){
            for(ComputeRuleLog dragRuleLogList : dragRuleLogLists){
                ComputeRuleLog dragRuleLogList1 = JSON.toJavaObject(JSON.parseObject(dragRuleLogList.getSnapshot()), ComputeRuleLog.class);
                dragRuleLogList.setSupplierName(supplierMapper.getNameByCode(dragRuleLogList1.getSupplierCode()));
            }
        }

        pageResultBO.setPageSize(page.getPageSize());
        pageResultBO.setPageNo(page.getPageNo());
        pageResultBO.setTotalRecord(page.getTotalRecord());
        pageResultBO.setDataList(dragRuleLogLists);
        return pageResultBO;
    }*/
}
